#!/bin/bash
q1(){
	i=0
	j=0
	z=0
	free -m|tail -n +2| while read a b c d e 
	do
		i=$(($i+$b))
		j=$(($j+$d))
		z=$(($z+$c))
		if [ $a = Swap: ]
		then
			r=$(echo "scale=2;$z/$i*100"|bc)
			echo "total:$i free:$j rate:$r%"
			if [[ $r>80 ]]
			then
				echo "警告"
			else
				echo "正常"
			fi
		fi
	done
}
q2(){
	for i in `seq 1 255`
	do
		( ip_full=192.168.0.$i
		if ping -c1 $ip_full &>/dev/null
		then
			echo "$ip_full" >>up.txt
		else
			echo "$ip_full" >>down.txt
		fi
		)&
	done
wait
}
q3(){
	cp /etc/passwd/ /lianxi/passwd
	n=`diff /etc/passwd/ /lianxi/passwd/|wc -l`
	[[  n-eq 0 ]] && echo"没有改变"||echo "/ect/passwd文件被改变"
}
q4(){
	pidof nginx && echo "nginx is running" || echo "nginx is down"
}

echo "==========功能==========="
echo "==1.监控内存使用情况"
echo "==2.扫描ip"
echo "==3.监控文件/etc/passwd"
echo "==4.监控nginx进程"
read -p "请选择需要实现的功能：" choice
case $choice in
1)
	q1
;;
2)
	q2
;;
3)
	q3
;;
4)
	q4
;;
esac
